SCL Scripts

An SCL Script is a file containing a sequence of SCL statements that are executed top-to-bottom, much like typing them into the console one by one. Scripts are useful for automating multi-step tasks that would be tedious to enter interactively.

Difference from modules

Module Script
Contents Declarations Executable statements
Compiled as One unit One unit per statement group
Executed when Never; its values are computed on first use Top to bottom, when the script is run
Order of definitions Irrelevant Significant
Can declare types, classes, instances Yes No
Can import modules Yes Yes
Typical use Library code, reusable utilities One-off automation, batch operations

The two are compiled by different front ends and accept different language features. 1.18 Modules vs. scripts documents the differences exhaustively; read it before moving code from one to the other.

Creating a script

  1. In the Model Browser, right-click the library node where you want the script.
  2. Select New → SCL Script.
  3. Enter a name for the script.

The script editor opens. Write SCL statements, one per line (or use blank lines for readability). Statements are executed in order.

Running a script

Right-click the script node in the Model Browser and select Run SCL Script. Output from print and other printing functions appears in the SCL Script Output window.

Running a script from the console

Any plain-text .scl file on the file system can be executed from the SCL Console:

runFromFile "c:/path/to/myscript.scl"

Remember that \ is an escape character in strings; either use / as the path separator or double the backslashes:

runFromFile "c:/data/setup.scl"
runFromFile "c:\\data\\setup.scl"

Example script

The following script imports Apros/Legacy, creates two points and a pipe, and prints a confirmation message:

import "Apros/Legacy"

aadd "MYDIAGRAM" "Point" "PO01" (50.0, 50.0)
amodi "PO01" "PO11_PRESSURE" 0.2

aadd "MYDIAGRAM" "Point" "PO02" (100.0, 50.0)
amodi "PO02" "PO11_PRESSURE" 0.1

aadd "MYDIAGRAM" "Pipe" "PIP01" (75.0, 50.0)
amodi "PIP01" "PI12_CONNECT_POINT_1" "PO01"
amodi "PIP01" "PI12_CONNECT_POINT_2" "PO02"

print "Model configuration complete."

Importing modules in scripts

Modules are imported at the top of the script using the same syntax as in modules:

import "Simantics/DB"
import "Apros/Legacy"

The imported names are available for the rest of the script's statements.